package thread;

public class ThreadDemo3 {
    public static void main(String[] args) {
    //第一种方式:继承Thread重写run方法
        Thread t1 = new Thread(){
            public void run(){
                for (int i = 0; i < 1000; i++) {
                    System.out.println("1");
                }
            }
        };

    //第二种方式:实现Runnable接口重写run方法
        Runnable r2 = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    System.out.println("2_1");
                }
            }
        };
        Thread t2 = new Thread(r2);

        //Runnable可以使用lambda表达式创建
        Runnable r3 = () -> {for (int i = 0; i < 1000; i++) System.out.println("2_2");};
        Thread t3 = new Thread(r3);

        t1.start();
        t2.start();
        t3.start();
    }
}
